import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:rc_widget/rc_widget.dart';

import 'package:flutter_study/widgets/public/themes/index.dart';
class AppTopBar extends StatelessWidget implements PreferredSizeWidget {
  const AppTopBar({
    super.key,
    this.title = ' ',
    required this.backable, 
    this.backIconColor, 
    this.backgroundColor, 
    this.titleStyle, 
    required this.actions, 
    required this.bottomLine,
  });

  final String title;
  final bool backable;
  final Color? backIconColor;
  final Color? backgroundColor;
  final TextStyle? titleStyle;
  final List<Widget> actions;
  final bool bottomLine;

    @override
  // TODO: implement preferredSize
  Size get preferredSize => Size.fromHeight(88.h);

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: BoxDecoration(color: backIconColor ?? AppThemes.of().colors.background1),
      child: SafeArea(
        child: SizedBox.expand(
        child: Stack(
          alignment: Alignment.center,
          children: [
            _buildLeft(),
            _buildTitle(),
            _buildRight(),
            if(bottomLine) _buildBottomLine(),
          ],
          ),
      ),
      ),
    );
  }
  Widget _buildLeft(){
    if(!backable) return const SizedBox();
    return Positioned(
      left:4,
      child: RcIconButton(
        icon: Icons.arrow_back_ios,
        color: backIconColor,
        iconSize: 40.sp,
        dimension: 88.h,
        onTap:Get.back,
      ),
    );
  }
  
 Widget _buildTitle() {
  return DefaultTextStyle(style: titleStyle ?? AppThemes.of().w700Text132,
   child:Text(
    title,
    ),
    );
 }
 
 Widget _buildRight() {
  return Positioned(
    right: 10,
    child: Row(
      children: actions,
    ),
  );
 }
 

 Widget _buildBottomLine(){
  return Positioned(
    left:0,
    right: 0,
    bottom: 0,
    child:Container(decoration: AppThemes.of().bottomBorder1,)
    );
 }


}